package demo.messaging.client.ui;

import demo.messaging.client.core.ApplicationContext;
import demo.messaging.client.core.ClientManager;
import demo.messaging.client.core.IMessageEventListener;
import demo.messaging.client.core.MessageEvent;
import demo.messaging.client.core.MessageEvent.EnumMessageEventType;
import demo.util_ui.client.ui.SimpleDialog;
import demo.util_ui.client.ui.YesNoDialog;

public class IncomingInvitationUI extends YesNoDialog implements
		IMessageEventListener {

	public IncomingInvitationUI() {
		super("Accept", "Decline");
	}

	@Override
	public void onMessageEvent(final MessageEvent event) {
		if (event.getType() == EnumMessageEventType.invitationReceived) {

			resetContent("You've got an invitation !", event.getMessage()
					.getSender()
					+ " sends an invitation: " + event.getMessage().getText(),
					null);
			center();

		} else if (this.isShowing()

		&& event.getType() == EnumMessageEventType.cancelReceived) {

			hide();
			((SimpleDialog) ApplicationContext.getBean("infoDialog")).showInfo(
					"Notification", event.getMessage().getSender()
							+ " has cancelled his (her) invitation.");
		}
	}

	@Override
	protected void onNo() {
		ClientManager.getClientManager().sendCancelMessageToInvitor();
	}

	@Override
	protected void onYes() {
		ClientManager.getClientManager().sendAcceptance();
		hide();

	}

}
